package com.jcl.recruit.console.mapper.provider;

import com.jcl.recruit.console.model.ConsoleDbServer;
import com.jcl.recruit.mapper.provider.SqlProvider;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @ClassName ConsoleCorpInfoProvider

 * @Author yyliu
 * @Date 2018/12/13 16:54
 * @Version 1.0
 **/
public class ConsoleDbServerProvider implements SqlProvider<ConsoleDbServer> {

    private static final String TABLE_NAME = "t_console_db_server";

    public String insert(ConsoleDbServer entity) {
        BEGIN();
        INSERT_INTO(TABLE_NAME);
        if (entity.getServerName() != null) {
            VALUES("server_name", "#{serverName,jdbcType=VARCHAR}");
        }

        if (entity.getDbIp() != null) {
            VALUES("db_ip", "#{dbIp,jdbcType=VARCHAR}");
        }

        if (entity.getDbPort() != null) {
            VALUES("db_port", "#{dbPort,jdbcType=VARCHAR}");
        }

        if (entity.getDbName() != null) {
            VALUES("db_name", "#{dbName,jdbcType=VARCHAR}");
        }

        if (entity.getDbUsername() != null) {
            VALUES("db_username", "#{dbUsername,jdbcType=VARCHAR}");
        }

        if (entity.getDbPassword() != null) {
            VALUES("db_password", "#{dbPassword,jdbcType=VARCHAR}");
        }

        if (entity.getDbUrlParam() != null) {
            VALUES("db_url_param", "#{dbUrlParam,jdbcType=VARCHAR}");
        }

        if (entity.getDbUrl() != null) {
            VALUES("db_url", "#{dbUrl,jdbcType=VARCHAR}");
        }

        if (entity.getPrefix() != null) {
            VALUES("prefix", "#{prefix,jdbcType=VARCHAR}");
        }

        if (entity.getTotal() != null) {
            VALUES("total", "#{total,jdbcType=INTEGER}");
        }

        if (entity.getCorpStart() != null) {
            VALUES("corp_start", "#{corpStart,jdbcType=INTEGER}");
        }

        if (entity.getCorpEnd() != null) {
            VALUES("corp_end", "#{corpEnd,jdbcType=INTEGER}");
        }
        if (entity.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }


        return SQL();
    }

    public String updateByPrimaryKey(ConsoleDbServer entity) {
        BEGIN();
        UPDATE(TABLE_NAME);

        if (entity.getServerName() != null) {
            SET("server_name = #{serverName,jdbcType=VARCHAR}");
        }

        if (entity.getDbIp() != null) {
            SET("db_ip = #{dbIp,jdbcType=VARCHAR}");
        }

        if (entity.getDbPort() != null) {
            SET("db_port = #{dbPort,jdbcType=VARCHAR}");
        }

        if (entity.getDbName() != null) {
            SET("db_name = #{dbName,jdbcType=VARCHAR}");
        }

        if (entity.getDbUsername() != null) {
            SET("db_username = #{dbUsername,jdbcType=VARCHAR}");
        }

        if (entity.getDbPassword() != null) {
            SET("db_password = #{dbPassword,jdbcType=VARCHAR}");
        }

        if (entity.getDbUrlParam() != null) {
            SET("db_url_param = #{dbUrlParam,jdbcType=VARCHAR}");
        }

        if (entity.getDbUrl() != null) {
            SET("db_url = #{dbUrl,jdbcType=VARCHAR}");
        }

        if (entity.getPrefix() != null) {
            SET("prefix = #{prefix,jdbcType=VARCHAR}");
        }

        if (entity.getTotal() != null) {
            SET("total = #{total,jdbcType=INTEGER}");
        }

        if (entity.getCorpStart() != null) {
            SET("corp_start = #{corpStart,jdbcType=INTEGER}");
        }

        if (entity.getCorpEnd() != null) {
            SET("corp_end = #{corpEnd,jdbcType=INTEGER}");
        }

        if (entity.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }


        WHERE("id = #{id,jdbcType=INTEGER}");

        return SQL();
    }

}
